<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/session.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
    <LINK type="text/css" rel="stylesheet" href="${ctx}/css/default.css"/>
    <script type="text/javascript" src="${ctx}/js/xtable.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/RegionRpcService.js'></script>
    <script type='text/javascript' src='${ctx}/dwr/interface/MarketRpcService.js'></script>
    <script type="text/javascript" src="${ctx}/js/loading.js"></script>
</head>
<body>
<form>
	<center>
        <table style="width: 50%;" cellpadding="5" cellspacing="5">
            <tr>
                <td>
                    <select id="marketId" name="marketId" onchange="getRegionPage()">
			        </select>
                </td>
                <td>
                    <button type="button" onclick="submitRegion('')">添加区域</button>
                </td>
            </tr>
        </table>
    </center>
</form>

<SCRIPT LANGUAGE="JavaScript" >
    var regionThead = new Array(
        new XThead("区域名称"),
        new XThead("租赁类型"),
        new XThead("区域面积/车位数"),
        new XThead("每月单位租金(元)"),
        new XThead("市场名称"),
        new XThead("已租面积(车位)/全部面积(车位)"),
        new XThead("合计租金(元)"),
        new XThead("地理位置"),
        new XThead("操作")
    );

    var type_hash = {
        "1":"按面积",
        "2":"按车位"
    }
    var  type_unit = {
         "1": '平米',
         "2": '个'
    }

    var regionXTable = new XTable("region", regionThead, true);

    regionXTable.XTbodyArray = function (model) {


        var array = new Array(
            new XTbody("region", model.regionName),
            new XTbody("region", type_hash[model.regionType]),
            new XTbody("region", model.regionNum + type_unit[model.regionType]),
            new XTbody("region", model.regionRentFee),
            new XTbody("region", model.market.marketName),
            new XTbody("region", (model.regionNum - model.regionRestNum) + type_unit[model.regionType]+"/"+model.regionNum + type_unit[model.regionType] + "&nbsp;" + "<a href='#'  class='contact-input' onclick= callBackRegionContractList('"+ model.regionId +"')>详情</a>" ),
            new XTbody("region", model.regionRentFee * (model.regionNum - model.regionRestNum)),
            new XTbody("region", model.regionRemark),
            new XTbody("region", "<a href='#'  class='contact-input' onclick=submitRegion('"+ model.regionId +"')>编辑</a>", "string", null, null, "center")
        );
        return array;
    }


    function getRegionPage() {
        var region = new Region();
        region.marketId = dwr.util.getValue("marketId");
        RegionRpcService.selectRegionList(region, function (list) {
            regionXTable.addTable(list);
        });
    }
</SCRIPT>
</body>
</html>
<script>
    var market = new Market();
    market.marketId = "${marketId}";
    MarketRpcService.selectMarketList(market, callbackSelectMarketList);

    function callbackSelectMarketList(list) {
        dwr.util.addOptions("marketId", list, "marketId", "marketName");
        dwr.util.setValue("marketId", "${marketId}");
        getRegionPage();
    }


    function submitRegion(regionId){
        location = "${ctx}/market/region_manage.jsp?regionId=" + regionId;
    }

    function callBackRegionContractList(regionId){
        location = "${ctx}/market/region_contract_list.jsp?regionId=" + regionId
    }
</script>
